home *** CD-ROM | disk | FTP | other *** search
- Path: news.sprintlink.net!datalytics!news
- From: Rob Stewart <stew@datalytics.com>
- Newsgroups: comp.lang.c++
- Subject: Re: beginner question - typecasting
- Date: 4 Jan 1996 21:30:19 GMT
- Organization: Datalytics, Inc
- Message-ID: <4chgtb$ldg@gold.datalytics.com>
- References: <4cei1r$s02@sun.cis.smu.edu> <30EBCED7.774@sto.fdata.se>
- NNTP-Posting-Host: pc071.datalytics.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- Niklas Mellin <niklas.mellin@sto.fdata.se> wrote:
- >Damon Bowman wrote:
- >>
- >> When you are typecasting, is there any difference between:
- >>
- >> a = int(x)
- >> and
- >> a = (int) x
- >
- >[...]
- >
- >Yes the first is not type casting, but a "type conversion".
-
- No. The two are the same in effect. The difference in syntax
- allows for some changes introduced in C++'s syntax. I don't
- recall now the eact reason for the new syntax.
-
- >When x is a variables of built in types there is no
- >difference. But if x is a varible of some class for instance
- >the first form generates a call to that class' operator int(),
- >generating a compile time error message if there is no such
- >member function.
-
- There is no difference in behavior.
-
- >The 2nd form is an inheritance from plain C, and doesn't work
- >when x is of class type. It is also
- >not "safe", meaning that the compiler will not generate error
- >messages in certain situations, and you will get buggy code
- >or run time errors instead.
-
- Not at all correct.
-
- >
- [snip]
-
-
- --
- Robert Stewart | My opinions are usually my own.
- Datalytics, Inc.
- (513)226-7700
- stew@datalytics.com
-
-
-